import { adminLogin } from './../../api/admin'
import * as types from './../actionTypes'
const userAction = (values) => {
  return (dispatch) => {
   
    return new Promise(resolve => { // 将后续的业务逻辑交由组件
      adminLogin(values).then(res => {
      
        // 修改状态
        dispatch({
          type: types.CHANGE_ADMIN_NAME,
          payload: res.data.data.adminname
        })
        dispatch({
          type: types.CHANGE_LOGIN_STATE,
          payload: true
        })
        dispatch({
          type: types.CHANGE_ROLE,
          payload: res.data.data.role
        })
        dispatch({
          type: types.CHANGE_TOKEN,
          payload: res.data.data.token
        })
        resolve(res)
      })
    })
    
  }
}

export default userAction